<template>
  <BasicDrawer
    v-bind="$attrs"
    :showFooter="true"
    :showOkBtn="false"
    @register="registerDrawer"
    @close="handleClose"
    width="90%"
  >
    <template #title>
      <Icon :icon="getTitle.icon" class="pr-1 m-1" />
      <span> {{ getTitle.value }} </span>
    </template>
    <BasicTable @register="registerTable" />
  </BasicDrawer>
</template>
<script lang="ts" setup name="ViewsSysRoleAuthDataScope">
  import { ref, unref, computed } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { router } from '/@/router';
  import { Icon } from '/@/components/Icon';
  import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  import { BasicTable, BasicColumn, useTable, TableRowSelection } from '/@/components/Table';
  import { formAuthUser } from '/@/api/sys/role';
  import { userListData } from '/@/api/sys/user';

  const { t } = useI18n('sys.role');
  const { showMessage } = useMessage();
  const { meta } = unref(router.currentRoute);
  const record = ref<Recordable>({});
  const getTitle = computed(() => {
    const r = record.value;
    return {
      icon: meta.icon || 'ant-design:book-outlined',
      value: t('风险点评价详情')
    };
  });
  const listSelectRef = ref<any>(null);

  const tableColumns: BasicColumn[] = [
    {
      title: t('作业步骤'),
      dataIndex: 'loginCode',
      key: 'a.login_code',
      sorter: true,
      width: 100,
      slot: 'firstColumn',
    },
    {
      title: t('风险源'),
      dataIndex: 'userName',
      key: 'a.user_name',
      sorter: true,
      width: 100,
    },
    {
      title: t('危害描述'),
      dataIndex: 'email',
      key: 'a.email',
      width: 100,
    },
    {
      title: t('后果'),
      dataIndex: 'mobile',
      key: 'a.mobile',
      width: 100,
    },
    {
      title: t('现有控制措施'),
      dataIndex: 'mobile',
      key: 'a.mobile',
      width: 160,
    },
    {
      title: t('L'),
      dataIndex: 'userWeight',
      key: 'a.phone',
      width: 30,
    },
    {
      title: t('E'),
      dataIndex: 'userWeight',
      key: 'a.update_date',
      width: 30,
    },
    {
      title: t('C'),
      dataIndex: 'userWeight',
      key: 'a.update_date',
      width: 30,
    },
    {
      title: t('残余D'),
      dataIndex: 'userWeight',
      key: 'a.update_date',
      width: 50,
    },
  ];

  const [registerTable, { reload, getSelectRowKeys, setSelectedRowKeys }] = useTable({
    api: userListData,
    beforeFetch: (params) => {
      params.roleCode = record.value.roleCode;
      params.userType = record.value.userType;
      return params;
    },
    immediate: false,
    columns: tableColumns,
    showTableSetting: false,
    useSearchForm: false,
    canResize: true,
    resizeHeightOffset: 60,
  });

  const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
    setDrawerProps({ loading: true });
    const ret = '"1.车未停稳上下车；\n' +
      '2.乘车未系安全带；\n' +
      '3.乘车时与司机闲谈；\n' +
      '4.车辆超员、超速行驶；\n' +
      '5.部门监督检查不到位；\n' +
      '6.车辆安全部件故障失效；\n' +
      '7.雨雪天气驾驶机动车；\n' +
      '8.道路有坑洞。"';
    const res = {"count":28,"pageSize":20,"list":[{"id":"demo_ytrd","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2023-11-09 20:02","updateBy":"demo_ytrd","createDate":"2023-11-09 19:58","userWeight":0,"userCode":"demo_ytrd","oldLastLoginIp":"127.0.0.1","lastLoginIp":"127.0.0.1","mgrType":"0","refCode":"demo_ytrd","userName":"双重预防原型","lastLoginDate":"2023-11-09 20:01:30","refName":"原型图","userType":"employee","loginCode":"demo","mobile":"18666687770","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg","oldLoginDate":"2023-11-09 20:01:30"},{"id":"system","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2023-11-08 22:21","updateBy":"system","createDate":"2022-03-31 20:58","remarks":"开发者使用的最高级别管理员，主要用于开发和调试。","userWeight":0,"userCode":"system","oldLastLoginIp":"127.0.0.1","lastLoginIp":"127.0.0.1","mgrType":"0","userName":"超级管理员","lastLoginDate":"2023-11-09 20:42:35","userType":"none","loginCode":"system","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg","oldLoginDate":"2023-11-09 20:42:35"},{"id":"risk_ls8e","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2023-11-08 02:10","updateBy":"system","createDate":"2023-11-05 11:57","userWeight":0,"userCode":"risk_ls8e","oldLastLoginIp":"127.0.0.1","lastLoginIp":"127.0.0.1","mgrType":"2","refCode":"risk_ls8e","userName":"双重预防管理员","lastLoginDate":"2023-11-09 20:01:09","refName":"尚海峰","userType":"employee","loginCode":"risk","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg","oldLoginDate":"2023-11-09 20:01:09"},{"id":"工程设备","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2023-11-07 15:38","updateBy":"system","createDate":"2023-11-07 15:38","userWeight":0,"userCode":"工程设备","mgrType":"1","userName":"履带式推土机","userType":"none","loginCode":"工程设备","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user11_bdzh","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user11_bdzh","mgrType":"0","refCode":"user11_bdzh","email":"user@test.com","userName":"用户11","refName":"用户11","userType":"employee","loginCode":"user11","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user9_jo5m","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user9_jo5m","mgrType":"0","refCode":"user9_jo5m","email":"user@test.com","userName":"用户09","refName":"用户09","userType":"employee","loginCode":"user9","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user8_iiux","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user8_iiux","mgrType":"0","refCode":"user8_iiux","email":"user@test.com","userName":"用户08","refName":"用户08","userType":"employee","loginCode":"user8","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user7_u7yz","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user7_u7yz","mgrType":"0","refCode":"user7_u7yz","email":"user@test.com","userName":"用户07","refName":"用户07","userType":"employee","loginCode":"user7","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user6_ksry","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user6_ksry","mgrType":"0","refCode":"user6_ksry","email":"user@test.com","userName":"用户06","refName":"用户06","userType":"employee","loginCode":"user6","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user23_zff4","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user23_zff4","mgrType":"0","refCode":"user23_zff4","email":"user@test.com","userName":"用户23","refName":"用户23","userType":"employee","loginCode":"user23","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user22_79sr","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user22_79sr","mgrType":"0","refCode":"user22_79sr","email":"user@test.com","userName":"用户22","refName":"用户22","userType":"employee","loginCode":"user22","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user21_jjf1","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user21_jjf1","mgrType":"0","refCode":"user21_jjf1","email":"user@test.com","userName":"用户21","refName":"用户21","userType":"employee","loginCode":"user21","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user20_3bd7","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user20_3bd7","mgrType":"0","refCode":"user20_3bd7","email":"user@test.com","userName":"用户20","refName":"用户20","userType":"employee","loginCode":"user20","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user19_tvim","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user19_tvim","mgrType":"0","refCode":"user19_tvim","email":"user@test.com","userName":"用户19","refName":"用户19","userType":"employee","loginCode":"user19","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user18_aqob","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user18_aqob","mgrType":"0","refCode":"user18_aqob","email":"user@test.com","userName":"用户18","refName":"用户18","userType":"employee","loginCode":"user18","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user17_yjog","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user17_yjog","mgrType":"0","refCode":"user17_yjog","email":"user@test.com","userName":"用户17","refName":"用户17","userType":"employee","loginCode":"user17","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user16_tmwg","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user16_tmwg","mgrType":"0","refCode":"user16_tmwg","email":"user@test.com","userName":"用户16","refName":"用户16","userType":"employee","loginCode":"user16","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user15_vcf3","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user15_vcf3","mgrType":"0","refCode":"user15_vcf3","email":"user@test.com","userName":"用户15","refName":"用户15","userType":"employee","loginCode":"user15","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user14_qnee","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user14_qnee","mgrType":"0","refCode":"user14_qnee","email":"user@test.com","userName":"用户14","refName":"用户14","userType":"employee","loginCode":"user14","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"},{"id":"user13_k8p9","isNewRecord":false,"createBy":"system","status":"0","updateDate":"2022-03-31 20:58","updateBy":"system","createDate":"2022-03-31 20:58","userWeight":0,"phone":"053188888888","userCode":"user13_k8p9","mgrType":"0","refCode":"user13_k8p9","email":"user@test.com","userName":"用户13","refName":"用户13","userType":"employee","loginCode":"user13","mobile":"18555555555","corpCode_":"0","corpName_":"JeeSite","avatarUrl":"/ctxPath/static/images/user1.jpg"}],"pageNo":1}
    record.value = (res.role || {}) as Recordable;
    handleSuccess();
    setDrawerProps({ loading: false });
  });

  function handleForm() {
    listSelectRef.value.openSelectModal();
  }

  function handleSuccess() {
    reload();
  }

  async function handleClose() {
    closeDrawer();
  }
</script>
